package com.shuzi.MediaShare;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;

import com.shuzi.MediaShare.control.CacheDataManager;
import com.shuzi.MediaShare.model.MediaType;
import com.shuzi.MediaShare.model.MovieInfo;
import com.shuzi.MediaShare.utils.Util;

/**
 * 常量类
 * 
 * @author lung 下午2:20:53 2013
 */
public class Constant
{
	/** 用户 ID */
	public static String UID = "";

	/** 所有的类型 */
	public static List<MediaType> types = new ArrayList<MediaType>();

	public static Map<String, MediaType> tMap = new HashMap<String, MediaType>();

	/** 所有的类型键 */
	public static String[] typesStrings;

	/** 所有的下載狀態 */
	public static String[] downloadStates;

	/** 所有的上映时间 */
	public static String[] times;

	/** 所有的地区 */
	public static String[] areas;

	/** 屏幕宽度 */
	public static int WIDTH = 0;

	/** 屏幕高度 */
	public static int HEIGHT = 0;

	/** 设备码 */
	public static String IMEI = "";

	/** 是否登陆 */
	public static boolean isLogin = false;

	/** 历史记录 */
	public static List<MovieInfo> historyList;

	/** 历史记录 */
	public static Map<String, MovieInfo> historymMap;

	/** 本身ip地址 */
	public static String Ip;

	/**
	 * 初始化
	 * 
	 * @param context
	 */
	@SuppressWarnings("unchecked")
	public static void init(Context context)
	{
		typesStrings = context.getResources().getStringArray(R.array.types);
		WIDTH = context.getResources().getDisplayMetrics().widthPixels;
		HEIGHT = context.getResources().getDisplayMetrics().heightPixels;
		downloadStates = context.getResources().getStringArray(
				R.array.downloadStates);
		times = context.getResources().getStringArray(R.array.times);
		// areas = context.getResources().getStringArray(R.array.areas);
		TelephonyManager tm = (TelephonyManager) context
				.getSystemService(Context.TELEPHONY_SERVICE);
		IMEI = tm.getDeviceId();
		// Toast.makeText(context, IMEI, Toast.LENGTH_SHORT).show();
		historyList = (List<MovieInfo>) CacheDataManager.getInstance()
				.getCacheDataToFile(context, "HISTORY");

		if (historyList == null)
		{
			historyList = new ArrayList<MovieInfo>();
			CacheDataManager.getInstance().saveCachDataToFile(context,
					"HISTORY", historyList);
		}

		historymMap = new HashMap<String, MovieInfo>();
		for (int i = 0; i < historyList.size(); i++)
		{
			historymMap.put(historyList.get(i).getID(), historyList.get(i));
		}

		Ip = Util.setIp(context);

	}
}
